import { isFunction, isString } from '@guanwei/app-javascript'
import { isDev } from './env'

function _basePrint(type, ...args) {
  args.unshift(`[${ process.env.VUE_APP_TITLE }]: `)
  // eslint-disable-next-line no-console
  isFunction(console[type]) && console[type].apply(console, args)
}

export const log = (...args) => { isDev && _basePrint('log', ...args) }
export const warn = (...args) => { _basePrint('error', ...args) }
export const assert = (condition, message, ErrorLike = Error) => {
  if (!isString(message)) { message = JSON.stringify(message) }
  if (condition && message) { throw new ErrorLike(message) }
}
